var submit = 0
layui.use(['table', 'admin', 'ax','element','laydate'], function () {
    var $ = layui.$;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;
	var element = layui.element
    var laydate = layui.laydate;
    
    //执行一个laydate实例
    laydate.render({
      elem: '#condition' //指定元素
    });
	
	//tab切换
	element.on('tab(doTabBrief)',function(data){
		console.log(data.index)
	})

    var ToolWave = {
        tableId: "toolWaveTable"
    };

    var ToolExpress = {
        tableId: "toolExpressTable"
    };
    var ToolExpressSum = {
        tableId: "toolExpressSumTable"
    };
    var ToolTaskArrange = {
        tableId: "toolTaskArrangeTable"
    };
    var ToolExpressScan7 = {
        tableId: "toolExpressScanTable7"
    };
    var ToolExpressSumTask = {
        tableId: "toolExpressSumTaskTable"
    };
    var ToolExpressSumTask6 = {
        tableId: "toolExpressSumTaskTable6"
    };

    /**
     * 初始化表格的列
     */
    ToolWave.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'id', hide: true, title: '主键'},
            {field: 'waveName', sort: true, title: '作业日期'},
            {field: 'nodes', sort: true, title: '备注'},
            {field: 'createTime', sort: true, title: '创建时间'},
            {field: 'createUserName', sort: true, title: '创建用户'},
            {align: 'center', toolbar: '#tableBar', title: '操作'}
        ]];
    };

    /**
     * 点击查询按钮
     */
    ToolWave.search = function () {
        var queryData = {};
        queryData['condition'] = $("#condition").val();
        table.reload(ToolWave.tableId, {
            where: queryData, page: {curr: 1},
             done:function () {
            }
        });
    };

    /**
     * 导出excel按钮
     */
    ToolWave.exportExcel = function () {
        var checkRows = table.checkStatus(ToolWave.tableId);
        if (checkRows.data.length === 0) {
            Feng.error("请选择要导出的数据");
        } else {
            table.exportFile(tableResult.config.id, checkRows.data, 'xls');
        }
    };

    /**
     * 点击删除
     *
     * @param data 点击按钮时候的行数据
     */
    ToolWave.onDeleteItem = function (data) {
        var operation = function () {
            var ajax = new $ax(Feng.ctxPath + "/toolWave/delete", function (data) {
                Feng.success("删除成功!");
                table.reload(ToolWave.tableId);
                table.reload(ToolExpress.tableId);
                table.reload(ToolExpressSum.tableId);
                table.reload(ToolTaskArrange.tableId);
                table.reload(ToolExpressScan7.tableId);
                table.reload(ToolExpressSumTask.tableId);
                table.reload(ToolExpressSumTask6.tableId);
            }, function (data) {
                Feng.error("删除失败!" + data.responseJSON.message + "!");
            });
            ajax.set("id", data.id);
            ajax.start();
        };
        Feng.confirm("是否删除?", operation);
    };

    // 渲染表格
    var tableResult = table.render({
        elem: '#' + ToolWave.tableId,
        url: Feng.ctxPath + '/toolWave/list',
        page: true,
        limit: 30,
        height: 370,
        toolbar: '#toolbarfrom',
        cellMinWidth: 100,
        cols: ToolWave.initColumn()
    });

    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        ToolWave.search();
    });

    // 添加按钮点击事件
    $('#btnAdd').click(function () {
		submit = 0
        layer.open({
            type: 2,
            title: '新增每日统计',
            area: ['900px', '400px'],
            anim: 5,
            content: Feng.ctxPath + '/toolWave/add',
            end: function () {
				if(submit == 1){
	                table.reload(ToolWave.tableId);
				}
            }
        });
    });

    // 导出excel
    $('#btnExp').click(function () {
        ToolWave.exportExcel();
    });

    // 工具条点击事件
    table.on('tool(' + ToolWave.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;

        if (layEvent === 'edit') {
			submit = 0
	        layer.open({
	            type: 2,
	            title: '编辑每日统计',
	            area: ['900px', '400px'],
	            anim: 5,
	            content: Feng.ctxPath + '/toolWave/edit?id='+data.id,
	            end: function () {
					if(submit == 1){
		                table.reload(ToolWave.tableId);
					}
	            }
	        });
        } else if (layEvent === 'delete') {
            ToolWave.onDeleteItem(data);
        } else if (layEvent === 'work') {
        	window.location.href = Feng.ctxPath + '/toolWork/toWork?waveId='+data.id;
        }
    });
    
    /**
     * 初始化表格的列
     */
    ToolExpress.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'id', hide: true, title: '主键'},
            {field: 'customerName', sort: true, title: '客户'},
            {field: 'wellen', sort: true, title: '波次'},
            {field: 'v1', sort: true, title: '出库单号'},
            {field: 'orderNumber', sort: true, title: '快递单号'},
            {field: 'goodsNumber', sort: true, title: '商品组合', totalRowText: '合计：'},
            {field: 'num', sort: true, title: '组合数量', totalRow: true},
            {field: 'v2', sort: true, title: '重量', totalRow: true},
            {field: 'v3', sort: true, title: '快递公司'},
            {field: 'v4', sort: true, title: '省份'},
            {field: 'v5', sort: true, title: '城市'},
            {field: 'v6', sort: true, title: '区县'},
            {field: 'v7', sort: true, title: '街道'},
            {field: 'v8', sort: true, title: '地址'},
        ]];
    };

    /**
     * 初始化表格的列
     */
    ToolExpressSum.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'id', hide: true, title: '主键'},
            {field: 'customerName', sort: true, title: '客户'},
            {field: 'v1', sort: true, title: '序号'},
            {field: 'goodsNumber', sort: true, title: '商品组合', totalRowText: '合计：'},
            {field: 'num', sort: true, title: '组合数量'},
            {field: 'orderNum', sort: true, title: '组合单量', totalRow: true},
            {field: 'sumNum', sort: true, title: '组合总数量', totalRow: true},
        ]];
    };

    /**
     * 初始化表格的列
     */
    ToolTaskArrange.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'id', hide: true, title: '主键'},
            {field: 'groupNumber', sort: true, title: '小组编号（与小组拣选位保持一致）'},
            {field: 'groupUsers', sort: true, title: '小组人员'},
            {align: 'center', toolbar: '#tableBar8', title: '操作'}
        ]];
    };
    
    ToolExpressScan7.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'id', hide: true, title: '主键'},
            {field: 'state', sort: true, title: '状态',
            	templet: function(d){
            		if (d.state == '已更新'){
                    	return '<span style="color: #19be6b;">' + d.state + '</span>'
					} else {
                    	return '<span>' + d.state + '</span>'
					} 
            	}
        	},
            {field: 'v1', sort: true, title: '波次'},
            {field: 'orderNumber', sort: true, title: '快递单号'},
            {field: 'arrangeNumber', sort: true, title: '小组编号'},
            {field: 'userName', sort: true, title: '小组人员'},
            {field: 'handover', sort: true, title: '交接次数'},
            {field: 'v2', sort: true, title: '类型'},
            {field: 'v3', sort: true, title: '包材编号'},
            {align: 'center', toolbar: '#tableBar7', title: '操作'}
        ]];
    };
    
    /**
     * 初始化表格的列
     */
    ToolExpressSumTask.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'id', hide: true, title: '主键'},
            {field: 'customerName', sort: true, title: '客户'},
            {field: 'v2', sort: true, title: '波次'},
            {field: 'arrangeNumber', sort: true, title: '小组编号'},
            {field: 'userName', sort: true, title: '小组人员'},
            {field: 'v3', sort: true, title: '类型'},
            {field: 'goodsNumber', sort: true, title: '商品组合', totalRowText: '合计：'},
            {field: 'num', sort: true, title: '组合数量'},
            {field: 'v1', sort: true, title: '作业数量', totalRow: true},
            {field: 'sumNum', sort: true, title: '单量', totalRow: true},
            {field: 'v4', sort: true, title: '重量', totalRow: true},
            {align: 'center', toolbar: '#tableBar4', title: '操作'}
        ]];
    };
    
    /**
     * 初始化表格的列
     */
    ToolExpressSumTask6.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'id', hide: true, title: '主键'},
            {field: 'customerName', sort: true, title: '客户'},
            {field: 'arrangeNumber', sort: true, title: '小组编号'},
            {field: 'userName', sort: true, title: '小组人员', totalRowText: '合计：'},
            {field: 'v1', sort: true, title: '作业数量', totalRow: true},
            {field: 'sumNum', sort: true, title: '单量', totalRow: true},
        ]];
    };
    
    // 单击行事件
    table.on('row(' + ToolWave.tableId + ')', function (obj) {
        var data = obj.data;
		$('div[lay-id="' + ToolWave.tableId + '"]').find(".layui-table-body tr ").attr({ "style": "background:#FFFFFF" });//其他tr恢复原样
		$('div[lay-id="' + ToolWave.tableId + '"]').find(obj.tr.selector).attr({ "style": "background:#e6e6e6;" });//改变当前tr颜色
    	finddata(data.id);
    });
    
    var find = 0
    
    function finddata(id){
		$("#tabmsg").show()
    	$("#findid").val(id)
    	find++
	    // 渲染表格
	    var tableResult2 = table.render({
	        elem: '#' + ToolExpress.tableId,
	        url: Feng.ctxPath + '/toolExpress/list?waveId='+id,
	        page: true,
	        limit: 120,
	        height: 390,
	        totalRow: true,
	        toolbar: '#toolbarfrom',
			limits:[40,60,120,240,360,480,1500,3000,6000,9000],
	        cellMinWidth: 100,
	        cols: ToolExpress.initColumn()
	    });
	
	    // 渲染表格
	    var tableResult3 = table.render({
	        elem: '#' + ToolExpressSum.tableId,
	        url: Feng.ctxPath + '/toolExpressSum/list?waveId='+id,
	        page: true,
	        limit: 60,
	        height: 390,
	        totalRow: true,
	        toolbar: '#toolbarfrom',
			limits:[40,60,120,240,360,480],
	        cellMinWidth: 100,
	        cols: ToolExpressSum.initColumn()
	    });

	    // 渲染表格
	    var tableResult8 = table.render({
	        elem: '#' + ToolTaskArrange.tableId,
	        url: Feng.ctxPath + '/toolTaskArrange/list?waveId='+id,
	        page: true,
	        limit: 40,
	        height: 390,
	        toolbar: '#toolbarfrom',
	        cellMinWidth: 100,
	        cols: ToolTaskArrange.initColumn()
	    });
	    
	    // 渲染表格
	    var tableResult7 = table.render({
	        elem: '#' + ToolExpressScan7.tableId,
	        url: Feng.ctxPath + '/toolExpressScan/list?waveId='+id,
	        page: true,
	        limit: 1020,
	        height: 390,
	        totalRow: true,
	        toolbar: '#toolbarfrom',
			limits:[480,1020,1500,2000],
	        cellMinWidth: 100,
	        cols: ToolExpressScan7.initColumn()
	    });
	
	    // 渲染表格
	    var tableResult4 = table.render({
	        elem: '#' + ToolExpressSumTask.tableId,
	        url: Feng.ctxPath + '/toolExpressSumTask/listd?waveId='+id,
	        page: true,
	        limit: 1020,
	        height: 390,
	        totalRow: true,
	        toolbar: '#toolbarfrom',
			limits:[480,1020,1500,2000],
	        cellMinWidth: 100,
	        cols: ToolExpressSumTask.initColumn()
	    });
	
	    // 渲染表格
	    var tableResult6 = table.render({
	        elem: '#' + ToolExpressSumTask6.tableId,
	        url: Feng.ctxPath + '/toolExpressSumTask/listSum?waveId='+id,
	        page: true,
	        limit: 60,
	        height: 390,
	        totalRow: true,
	        toolbar: '#toolbarfrom',
			limits:[40,60,120,240,360,480],
	        cellMinWidth: 100,
	        cols: ToolExpressSumTask6.initColumn()
	    });
	    
	    /**
	     * 点击查询按钮
	     */
	    ToolExpress.search = function () {
	        var queryData = {};
	        queryData['condition'] = $("#condition2").val();
	        queryData['customerId'] = $("#customerId2").val();
	        queryData['wellen'] = $("#wellen2").val();
	        queryData['v1'] = $("#v12").val();
	        queryData['v2'] = $("#v22").val();
	        queryData['goodsNumber'] = $("#goodsNumber2").val();
	        table.reload(ToolExpress.tableId, {
	            where: queryData, page: {curr: 1},
	             done:function () {
	            }
	        });
	    };
	
	    /**
	     * 点击查询按钮
	     */
	    ToolExpressSum.search = function () {
	        var queryData = {};
	        queryData['customerId'] = $("#customerId3").val();
	        queryData['condition'] = $("#condition3").val();
	        queryData['num'] = $("#num3").val();
	        table.reload(ToolExpressSum.tableId, {
	            where: queryData, page: {curr: 1},
	             done:function () {
	            }
	        });
	    };

	    /**
	     * 点击查询按钮
	     */
	    ToolTaskArrange.search = function () {
	        var queryData = {};
	        queryData['condition'] = $("#condition8").val();
	        queryData['groupNumber'] = $("#groupNumber8").val();
	        table.reload(ToolTaskArrange.tableId, {
	            where: queryData, page: {curr: 1},
	             done:function () {
	            }
	        });
	    };
	    
	    /**
	     * 点击查询按钮
	     */
	    ToolExpressScan7.search = function () {
	        var queryData = {};
	        queryData['arrangeNumber'] = $("#arrangeNumber7").val();
	        queryData['v1'] = $("#v17").val();
	        queryData['condition'] = $("#condition7").val();
	        queryData['userName'] = $("#userName7").val();
	        queryData['state'] = $("#state7").val();
	        queryData['state2'] = $("#state72").val();
	        table.reload(ToolExpressScan7.tableId, {
	            where: queryData, page: {curr: 1},
	             done:function () {
	            }
	        });
	    };
	
	    /**
	     * 点击查询按钮
	     */
	    ToolExpressSumTask.search = function () {
	        var queryData = {};
	        queryData['arrangeNumber'] = $("#arrangeNumber4").val();
	        queryData['v2'] = $("#v24").val();
	        queryData['outNumber'] = $("#outNumber4").val();
	        queryData['orderNumber'] = $("#orderNumber4").val();
	        queryData['goodsNumber'] = $("#goodsNumber4").val();
	        queryData['condition'] = $("#condition4").val();
	        queryData['customerId'] = $("#customerId4").val();
	        table.reload(ToolExpressSumTask.tableId, {
	            where: queryData, page: {curr: 1},
	             done:function () {
	            }
	        });
	    };
	
	    /**
	     * 点击查询按钮
	     */
	    ToolExpressSumTask6.search = function () {
	        var queryData = {};
	        queryData['condition'] = $("#condition6").val();
	        queryData['customerId'] = $("#customerId6").val();
	        table.reload(ToolExpressSumTask6.tableId, {
	            where: queryData, page: {curr: 1},
	             done:function () {
	            }
	        });
	    };
    
	    /**
	     * 导出excel按钮
	     */
	    ToolExpress.exportExcel = function () {
	        var checkRows = table.checkStatus(ToolExpress.tableId);
	        if (checkRows.data.length === 0) {
	            Feng.error("请选择要导出的数据");
	        } else {
	            table.exportFile(tableResult2.config.id, checkRows.data, 'xls');
	        }
	    };
	
	    /**
	     * 导出excel按钮
	     */
	    ToolExpressSum.exportExcel = function () {
	        var checkRows = table.checkStatus(ToolExpressSum.tableId);
	        if (checkRows.data.length === 0) {
	            Feng.error("请选择要导出的数据");
	        } else {
	            table.exportFile(tableResult3.config.id, checkRows.data, 'xls');
	        }
	    };

	    /**
	     * 导出excel按钮
	     */
	    ToolTaskArrange.exportExcel = function () {
	        var checkRows = table.checkStatus(ToolTaskArrange.tableId);
	        if (checkRows.data.length === 0) {
	            Feng.error("请选择要导出的数据");
	        } else {
	            table.exportFile(tableResult8.config.id, checkRows.data, 'xls');
	        }
	    };
	
	    /**
	     * 导出excel按钮
	     */
	    ToolExpressSumTask.exportExcel = function () {
	        var checkRows = table.checkStatus(ToolExpressSumTask.tableId);
	        if (checkRows.data.length === 0) {
	            Feng.error("请选择要导出的数据");
	        } else {
	            table.exportFile(tableResult4.config.id, checkRows.data, 'xls');
	        }
	    };
	
	    /**
	     * 导出excel按钮
	     */
	    ToolExpressSumTask6.exportExcel = function () {
	        var checkRows = table.checkStatus(ToolExpressSumTask6.tableId);
	        if (checkRows.data.length === 0) {
	            Feng.error("请选择要导出的数据");
	        } else {
	            table.exportFile(tableResult6.config.id, checkRows.data, 'xls');
	        }
	    };
	    
	    if(find == 1){
		    table.on('tool(' + ToolTaskArrange.tableId + ')', function (obj) {
		        var data = obj.data;
		        var layEvent = obj.event;
		
		        if (layEvent === 'edit8'){
		        	submit = 0
			        layer.open({
			            type: 2,
			            title: '修改工作安排',
			            area: ['1000px', '600px'],
			            anim: 5,
			            content: Feng.ctxPath + '/toolTaskArrange/edit?id='+data.id,
			            end: function () {
			            	if(submit == 1){
			                	table.reload(ToolTaskArrange.tableId);
			            	}
			            }
			        });
				} else if (layEvent === 'delete8'){
			        var operation = function () {
			            var ajax = new $ax(Feng.ctxPath + "/toolTaskArrange/delete", function (data) {
			                Feng.success("删除成功!");
			                table.reload(ToolTaskArrange.tableId);
			            }, function (data) {
			                Feng.error("删除失败!" + data.responseJSON.message + "!");
			            });
			            ajax.set("id", data.id);
			            ajax.start();
			        };
			        Feng.confirm("是否删除?", operation);
				}
		    });
		    table.on('tool(' + ToolExpressSumTask.tableId + ')', function (obj) {
		        var data = obj.data;
		        var layEvent = obj.event;
		
		        if (layEvent === 'mingxi4'){
		        	submit = 0
			        layer.open({
			            type: 2,
			            title: '明细',
			            area: ['1000px', '550px'],
			            anim: 5,
			            content: Feng.ctxPath + '/toolExpressSumTask?waveId='+$("#findid").val()+"&goodsNumber="+data.goodsNumber+"&arrangeId="+data.arrangeId+"&userName="+data.userName+"&v2="+data.v2+"&customerId="+data.customerId+"&v3="+data.v3,
			            end: function () {
			            	if(submit == 1){
			                	table.reload(ToolExpressSumTask.tableId);
			                	table.reload(ToolExpressSumTask6.tableId);
			            	}
			            }
			        });
				}
		    });
			 // 导入excel
			 $('#btnExpimport').click(function () {
				submit = 0
		        layer.open({
		            type: 2,
		            title: '快递明细导入',
		            area: ['1000px', '600px'],
		            anim: 5,
		            content: Feng.ctxPath + '/toolExpress/toimportExcel?waveId='+$("#findid").val(),
		            end: function () {
						if(submit == 1){
			                table.reload(ToolExpress.tableId);
			                table.reload(ToolExpressSum.tableId);
						}
		            }
		        });
			 });
			 // 导入excel
			 $('#btnExpimport8').click(function () {
				submit = 0
		        layer.open({
		            type: 2,
		            title: '工作安排导入',
		            area: ['1000px', '600px'],
		            anim: 5,
		            content: Feng.ctxPath + '/toolExpress/toimportExcel8?waveId='+$("#findid").val(),
		            end: function () {
						if(submit == 1){
			                table.reload(ToolTaskArrange.tableId);
						}
		            }
		        });
			 });
			 // 导入excel
			 $('#btnExpimport7').click(function () {
				submit = 0
		        layer.open({
		            type: 2,
		            title: '已分配明细导入',
		            area: ['1000px', '600px'],
		            anim: 5,
		            content: Feng.ctxPath + '/toolExpress/toimportExcel3?waveId='+$("#findid").val(),
		            end: function () {
						if(submit == 1){
		                	table.reload(ToolExpressScan7.tableId);
						}
		            }
		        });
			 });
		
			 // 导入excel
			 $('#btnExpimport4').click(function () {
				submit = 0
		        layer.open({
		            type: 2,
		            title: '预包、退货整理作业量导入',
		            area: ['1000px', '600px'],
		            anim: 5,
		            content: Feng.ctxPath + '/toolExpress/toimportExcel4?waveId='+$("#findid").val(),
		            end: function () {
						if(submit == 1){
			                table.reload(ToolExpressSumTask.tableId);
			                table.reload(ToolExpressSumTask6.tableId);
						}
		            }
		        });
			 });
	    
		    $('#btnday').click(function () {
		    	var checkStatus = table.checkStatus('toolExpressTable');
		        data = checkStatus.data;
		        if (data.length>0) {
		            var ids = [];
		            for (var i = 0; i < data.length; i++) {
		            	ids.push(data[i].id);
					}
		            layer.confirm('确定转入下一日吗?', function(index){
		            	layer.close(index);
		            	var msg;
		                $.ajax({
		                	url:Feng.ctxPath + "/toolExpress/btnday?ids="+ids+"&waveId="+$("#findid").val(),
							data:{},
		                	cache: false,
		                	dataType:"json",
		                	beforeSend:function(){
		                		msg = layer.msg('提交中。。。请耐心等待', {
		                			  icon: 16,
		                			  shade: [0.2,'#000'], //0.1透明度的白色背景
		                			  time: false
		                		});
		                	},
		                	success:function(data){
		                    	layer.close(msg); 
		                		if (data.success) {
				                	Feng.success("转入成功!");
				                	table.reload(ToolExpress.tableId);
				                	table.reload(ToolWave.tableId);
								} else {
			                    	Feng.error("转入失败!" + data.message + "!");
								}
		                	},
		                	error:function(data){
		                    	layer.close(msg); 
		                        Feng.error("操作失败！" + data.responseJSON.message)
		                	}
		                })
		            }); 
				} else {
					layer.alert('请至少选中一条数据');
				}
		    });
	    
		    $('#btnRevoke').click(function () {
		    	var checkStatus = table.checkStatus('toolExpressTable');
		        data = checkStatus.data;
		        if (data.length>0) {
		            var ids = [];
		            for (var i = 0; i < data.length; i++) {
		            	ids.push(data[i].id);
					}
		            var operation = function () {
		                var ajax = new $ax(Feng.ctxPath + "/toolExpress/btnRevoke?ids="+ids, function (data) {
			                if(data.success){
			                	Feng.success("删除成功!");
			                	table.reload(ToolExpress.tableId);
			                } else {
			                    Feng.error("删除失败!" + data.message + "!");
			                }
		                }, function (data) {
		                    Feng.error("删除失败!" + data.responseJSON.message + "!");
		                });
		                ajax.start();
		            };
		            Feng.confirm("是否删除选中明细?", operation);
				} else {
					layer.alert('请至少选中一条数据');
				}
		    });
	    
		    $('#btnRevoke8').click(function () {
		    	var checkStatus = table.checkStatus('toolTaskArrangeTable');
		        data = checkStatus.data;
		        if (data.length>0) {
		            var ids = [];
		            for (var i = 0; i < data.length; i++) {
		            	ids.push(data[i].id);
					}
		            var operation = function () {
		                var ajax = new $ax(Feng.ctxPath + "/toolTaskArrange/btnRevoke?ids="+ids, function (data) {
			                if(data.success){
			                	Feng.success("删除成功!");
			                	table.reload(ToolTaskArrange.tableId);
			                } else {
			                    Feng.error("删除失败!" + data.message + "!");
			                }
		                }, function (data) {
		                    Feng.error("删除失败!" + data.responseJSON.message + "!");
		                });
		                ajax.start();
		            };
		            Feng.confirm("是否删除选中安排?", operation);
				} else {
					layer.alert('请至少选中一条数据');
				}
		    });
	    
		    $('#btnRevoke82').click(function () {
	            var operation = function () {
	                var ajax = new $ax(Feng.ctxPath + "/toolTaskArrange/btnRevoke72?waveId="+$("#findid").val(), function (data) {
		                if(data.success){
		                	Feng.success("清空成功!");
			                table.reload(ToolTaskArrange.tableId);
		                } else {
		                    Feng.error("清空失败!" + data.message + "!");
		                }
	                }, function (data) {
	                    Feng.error("清空失败!" + data.responseJSON.message + "!");
	                });
	                ajax.start();
	            };
	            Feng.confirm("是否清空明细?", operation);
		    });
	    
		    $('#btnRevoke2').click(function () {
	            var operation = function () {
	                var ajax = new $ax(Feng.ctxPath + "/toolExpress/btnRevoke2?waveId="+$("#findid").val(), function (data) {
		                if(data.success){
		                	Feng.success("清空成功!");
			                table.reload(ToolExpress.tableId);
			                table.reload(ToolExpressSum.tableId);
		                } else {
		                    Feng.error("清空失败!" + data.message + "!");
		                }
	                }, function (data) {
	                    Feng.error("清空失败!" + data.responseJSON.message + "!");
	                });
	                ajax.start();
	            };
	            Feng.confirm("是否清空明细?", operation);
		    });
	    
		    $('#btnRevoke72').click(function () {
	            var operation = function () {
	                var ajax = new $ax(Feng.ctxPath + "/toolExpressScan/btnRevoke72?waveId="+$("#findid").val(), function (data) {
		                if(data.success){
		                	Feng.success("清空成功!");
		                	table.reload(ToolExpressScan7.tableId);
			                table.reload(ToolExpressSumTask.tableId);
			                table.reload(ToolExpressSumTask6.tableId);
		                } else {
		                    Feng.error("清空失败!" + data.message + "!");
		                }
	                }, function (data) {
	                    Feng.error("清空失败!" + data.responseJSON.message + "!");
	                });
	                ajax.start();
	            };
	            Feng.confirm("是否清空明细?", operation);
		    });
		    
		    $('#btnRevoke4').click(function () {
	            var operation = function () {
	                var ajax = new $ax(Feng.ctxPath + "/toolExpressSumTask/deletetask?waveId="+$("#findid").val(), function (data) {
		                if(data.success){
		                	Feng.success("删除成功!");
			                table.reload(ToolExpressSumTask.tableId);
			                table.reload(ToolExpressSumTask6.tableId);
		                } else {
		                    Feng.error("删除失败!" + data.message + "!");
		                }
	                }, function (data) {
	                    Feng.error("删除失败!" + data.responseJSON.message + "!");
	                });
	                ajax.start();
	            };
	            Feng.confirm("确定清空作业吗?", operation);
		    });
	    
		    table.on('tool(' + ToolExpressScan7.tableId + ')', function (obj) {
		        var data = obj.data;
		        var layEvent = obj.event;
		
		        if (layEvent === 'edit7'){
		        	submit = 0
			        layer.open({
			            type: 2,
			            title: '修改已配明细',
			            area: ['1000px', '550px'],
			            anim: 5,
			            content: Feng.ctxPath + '/toolExpressScan/edit?id='+data.id,
			            end: function () {
			            	if(submit == 1){
			                	table.reload(ToolExpressScan7.tableId);
			            	}
			            }
			        });
				}
		    });

		    $('#btnRevoke7').click(function () {
		    	var checkStatus = table.checkStatus('toolExpressScanTable7');
		        data = checkStatus.data;
		        if (data.length>0) {
		            var ids = [];
		            for (var i = 0; i < data.length; i++) {
		            	ids.push(data[i].id);
					}
		            var operation = function () {
		                var ajax = new $ax(Feng.ctxPath + "/toolExpressScan/btnRevoke?ids="+ids, function (data) {
			                if(data.success){
			                	Feng.success("删除成功!");
			                	table.reload(ToolExpressScan7.tableId);
			                } else {
			                    Feng.error("删除失败!" + data.message + "!");
			                }
		                }, function (data) {
		                    Feng.error("删除失败!" + data.responseJSON.message + "!");
		                });
		                ajax.start();
		            };
		            Feng.confirm("是否删除选中明细?", operation);
				} else {
					layer.alert('请至少选中一条数据');
				}
		    });
		    
		    $('#copyOrder').click(function () {
		    	var checkStatus = table.checkStatus('toolExpressTable');
		        data = checkStatus.data;
		        if (data.length>0) {
					var orders = "";
		            for (var i = 0; i < data.length; i++) {
						orders += data[i].orderNumber;
						orders += "\n";
					}
					// 获取要复制的文本
					const textToCopy = orders;
					
					// 创建一个临时的textarea元素，并将文本内容设置为要复制的文本
					const tempTextarea = document.createElement("textarea");
					tempTextarea.value = textToCopy;
					
					// 将textarea添加到DOM中
					document.body.appendChild(tempTextarea);
					
					// 选中textarea中的文本
					tempTextarea.select();
					
					// 执行复制命令
					document.execCommand("copy");
					
					// 删除临时创建的textarea元素
					document.body.removeChild(tempTextarea);
					
                	Feng.success("复制成功!");
				} else {
					layer.alert('请至少选中一条数据');
				}
		    });
	    
		    $('#gongzi4').click(function () {
	            layer.confirm('确定生成工资吗？', function(index){
	            	layer.close(index);
	            	var msg;
	                $.ajax({
	                	url:Feng.ctxPath + "/toolExpressSumTask/batchassign?waveId="+$("#findid").val(),
						data:{},
	                	cache: false,
	                	dataType:"json",
	                	beforeSend:function(){
	                		msg = layer.msg('提交中。。。请耐心等待', {
	                			  icon: 16,
	                			  shade: [0.2,'#000'], //0.1透明度的白色背景
	                			  time: false
	                		});
	                	},
	                	success:function(data){
	                    	layer.close(msg); 
	                		if (data.success) {
	                        	Feng.success("操作成功!");
							} else {
	  		                    Feng.error("操作失败！"+data.message);
							}
	                	},
	                	error:function(data){
	                    	layer.close(msg); 
	                        Feng.error("操作失败！" + data.responseJSON.message)
	                	}
	                })
	            }); 
		    });
		    
		    $('#updateStock4').click(function () {
		        layer.open({
		            type: 2,
		            title: '更新系统库存',
		            area: ['850px', '600px'],
		            anim: 5,
		            content: Feng.ctxPath + '/toolWave/toupdateStock?waveId='+$("#findid").val(),
		        });
		    });
	    
		    $('#btnUpdate7').click(function () {
	            layer.confirm('确定批量更新作业量吗？', function(index){
	            	layer.close(index);
	            	var msg;
	                $.ajax({
	                	url:Feng.ctxPath + "/toolExpressScan/btnUpdate?waveId="+$("#findid").val(),
						data:{},
	                	cache: false,
	                	dataType:"json",
	                	beforeSend:function(){
	                		msg = layer.msg('提交中。。。请耐心等待', {
	                			  icon: 16,
	                			  shade: [0.2,'#000'], //0.1透明度的白色背景
	                			  time: false
	                		});
	                	},
	                	success:function(data){
	                    	layer.close(msg); 
	                		if (data.success) {
	                        	Feng.success("操作成功!");
			                	table.reload(ToolExpressScan7.tableId);
				                table.reload(ToolExpressSumTask.tableId);
				                table.reload(ToolExpressSumTask6.tableId);
							} else {
	  		                    Feng.error("操作失败！"+data.message);
							}
	                	},
	                	error:function(data){
	                    	layer.close(msg); 
	                        Feng.error("操作失败！" + data.responseJSON.message)
	                	}
	                })
	            }); 
		    });
		    
		    $('#btnRevoke3').click(function () {
		    	var checkStatus = table.checkStatus('toolExpressSumTable');
		        data = checkStatus.data;
		        if (data.length>0) {
		            var ids = [];
		            for (var i = 0; i < data.length; i++) {
		            	ids.push(data[i].id);
					}
		            var operation = function () {
		                var ajax = new $ax(Feng.ctxPath + "/toolExpressSum/btnRevoke?ids="+ids, function (data) {
			                if(data.success){
			                	Feng.success("删除成功!");
			                	table.reload(ToolExpressSum.tableId);
				                table.reload(ToolExpressSumTask.tableId);
				                table.reload(ToolExpressSumTask6.tableId);
			                } else {
			                    Feng.error("删除失败!" + data.message + "!");
			                }
		                }, function (data) {
		                    Feng.error("删除失败!" + data.responseJSON.message + "!");
		                });
		                ajax.start();
		            };
		            Feng.confirm("是否删除选中明细?", operation);
				} else {
					layer.alert('请至少选中一条数据');
				}
		    });
	    
		    // 查询工资
		    $('#findgongzi4').click(function () {
		        layer.open({
		            type: 2,
		            title: '人员工资',
		            area: ['1050px', '600px'],
		            anim: 5,
		            content: Feng.ctxPath + '/toolTaskMoney?waveId='+$("#findid").val(),
		        });
		    });
	    
		    // 添加工作安排
		    $('#btnAdd8').click(function () {
		    	submit = 0
		        layer.open({
		            type: 2,
		            title: '新增工作安排',
		            area: ['1000px', '600px'],
		            anim: 5,
		            content: Feng.ctxPath + '/toolTaskArrange/add?waveId='+$("#findid").val(),
		            end: function () {
		            	if(submit == 1){
			                table.reload(ToolTaskArrange.tableId);
		            	}
		            }
		        });
		    });
		    
		    // 添加作业
		    $('#btnAdd4').click(function () {
		    	submit = 0
		        layer.open({
		            type: 2,
		            title: '新增作业明细',
		            area: ['1000px', '600px'],
		            anim: 5,
		            content: Feng.ctxPath + '/toolExpressSumTask/add?waveId='+$("#findid").val(),
		            end: function () {
		            	if(submit == 1){
			                table.reload(ToolExpressSumTask.tableId);
			                table.reload(ToolExpressSumTask6.tableId);
		            	}
		            }
		        });
		    });
	    
		    // 批量分配
		    $('#btnFenpei7').click(function () {
		    	var checkStatus = table.checkStatus('toolExpressScanTable7');
		        data = checkStatus.data;
		        if (data.length>0) {
		            var ids = [];
		            for (var i = 0; i < data.length; i++) {
		            	ids.push(data[i].id);
					}
		    		submit = 0
			        layer.open({
			            type: 2,
			            title: '批量分配',
			            area: ['1000px', '600px'],
			            anim: 5,
			            content: Feng.ctxPath + '/toolWave/choice_user?ids='+ids+"&waveId="+$("#findid").val(),
			            end: function () {
			            	if(submit == 1){
			                	table.reload(ToolExpressScan7.tableId);
			            	}
			            }
			        });
				} else {
					layer.alert('请至少选中一条数据');
				}
		    });
		    
		    // 单击行事件
		    table.on('row(' + ToolExpressSum.tableId + ')', function (obj) {
				$('div[lay-id="' + ToolExpressSum.tableId + '"]').find(".layui-table-body tr ").attr({ "style": "background:#FFFFFF" });//其他tr恢复原样
				$('div[lay-id="' + ToolExpressSum.tableId + '"]').find(obj.tr.selector).attr({ "style": "background:#e6e6e6" });//改变当前tr颜色
		    });
		
		    // 搜索按钮点击事件
		    $('#btnSearch2').click(function () {
		        ToolExpress.search();
		    });

		    // 搜索按钮点击事件
		    $('#btnSearch3').click(function () {
		        ToolExpressSum.search();
		    });

		    // 搜索按钮点击事件
		    $('#btnSearch8').click(function () {
		        ToolTaskArrange.search();
		    });
		
		    // 搜索按钮点击事件
		    $('#btnSearch7').click(function () {
		        ToolExpressScan7.search();
		    });
		
		    // 搜索按钮点击事件
		    $('#btnSearch4').click(function () {
		        ToolExpressSumTask.search();
		    });
		
		    // 搜索按钮点击事件
		    $('#btnSearch6').click(function () {
		        ToolExpressSumTask6.search();
		    });
		
		    // 导出excel
		    $('#btnExp2').click(function () {
		        ToolExpress.exportExcel();
		    });
		
		    // 导出excel
		    $('#btnExp3').click(function () {
		        ToolExpressSum.exportExcel();
		    });
		
		    // 导出excel
		    $('#btnExp8').click(function () {
		        ToolTaskArrange.exportExcel();
		    });
		
		    // 导出excel
		    $('#btnExp4').click(function () {
		        ToolExpressSumTask.exportExcel();
		    });
		
		    // 导出excel
		    $('#btnExp6').click(function () {
		        ToolExpressSumTask6.exportExcel();
		    });
    
	    }
    }
    
});
